<template>
  <div>
    <van-form @submit="onSubmit">
        <van-field v-model="userName" label="用户名" name="userName" placeholder="请输入用户名" :rules="[{ required: true, message: '请填写用户名' }]"/>
        <van-field v-model="password" label="用户名" name="password" placeholder="请输入密码"  :rules="[{ required: true, message: '请输入密码' }]"/>
        <van-button round type="info" native-type="submit" class="submit">提交</van-button>
    </van-form>
  </div>
</template>

<script>
export default {
  data () {
    return {
      userName: '',
      password: ''
    }
  },
  methods: {
    onSubmit (values) {
      const userInfo = {
        userName: 'sun',
        avatar: 'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=2121278104,33728762&fm=26&gp=0.jpg'
      }
      const accessToken = '5fdsfdsfdsf3ds21f'
      localStorage.setItem('userInfo', JSON.stringify(userInfo))
      localStorage.setItem('accessToken', accessToken)
      // 验证
      if (this.$route.query.path) {
        this.$router.push(this.$route.query.path)
      } else {
        this.$router.push('/home')
      }
    }
  }

}
</script>

<style lang="scss" scoped>
  .submit{
    width: 90%;
    margin: 16px;
  }
</style>
